package com.study.spring.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * TODO
 *
 * @author: zhang
 * @version: 3.0
 * @date: 2019-08-25 10:16:59
 * @since 1.8
 **/
public class TestThread {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestThread.class);


    private static boolean toBeStopped = true;

    public static void main(String[] args) {
        testVolatile();
    }

    private static void testVolatile() {


        new Thread(new Runnable() {
            @Override
            public void run() {
                toBeStopped = !toBeStopped;
                LOGGER.info("1");
            }
        }, "aa").start();


        new Thread(new Runnable() {
            @Override
            public void run() {
                if (!toBeStopped) {
                    LOGGER.info("2");
                }
            }

        }, "bb").start();

    }


}
